package com.创建型模型.D单例模式;

/**
 * @author zhangjiawen
 * @Date: 2022/6/1 11:12
 */
public class LazyMan {

    public volatile static LazyMan lazyMan=null;

    private LazyMan(){
        System.out.println(Thread.currentThread().getName()+"初始化……");
    }


    public static LazyMan getInstance(){
        if (lazyMan==null){

            synchronized (LazyMan.class){
                if (lazyMan==null) {
                    lazyMan = new LazyMan();
                }
            }
        }

        return lazyMan;

    }


    public static void main(String[] args) {
        for (int i = 0; i <10 ; i++) {
            new Thread(()->{
                LazyMan.getInstance();

            }).start();
        }
    }

}
